package com.hui.admin.utils.redis;


import cn.hutool.extra.spring.SpringUtil;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

@Component
public class RedisCaptchaUtil {

    private static final StringRedisTemplate redisTemplate = SpringUtil.getBean(StringRedisTemplate.class);

    // 存储验证码（带过期时间）
    public static void setCaptcha(String uuid, String code, long expireSeconds) {
        redisTemplate.opsForValue().set("captcha:" + uuid, code, expireSeconds, TimeUnit.SECONDS);
    }

    // 获取验证码
    public static String getCaptcha(String uuid) {
        return redisTemplate.opsForValue().get("captcha:" + uuid);
    }

    // 删除验证码
    public static void deleteCaptcha(String uuid) {
        redisTemplate.delete("captcha:" + uuid);
    }
}
